package com.evan.kdl.test.day01;

import com.evan.kdl.util.CommonUtils;

import java.util.concurrent.CompletableFuture;

/**
 * @author huangzhongliang
 * @time 2024/01/04 16:14
 * 编排2个依赖关系的异步任务 thenCompose()
 */
public class ThenComposeDemo {


    public static CompletableFuture<String> readFileFuture(String fileName) {
        return CompletableFuture.supplyAsync(() -> {
            String filterWordsContent = CommonUtils.readFile(fileName);
            return filterWordsContent;
        });
    }

    public static CompletableFuture<String[]> splitFuture(String context) {
        return CompletableFuture.supplyAsync(() -> {
            String[] filterWords = context.split(",");
            return filterWords;
        });
    }

    public static void main(String[] args) {
        CompletableFuture<CompletableFuture<String[]>> future = readFileFuture("F:\\idea-workspace-personal\\juc-springboot-demo\\src\\main\\resources\\filter_words.txt")
                .thenApply((context) -> {
                    return splitFuture(context);
                });
    }
}
